package com.jbarreto.queue;

import javax.annotation.PreDestroy;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 * Message-Driven Bean implementation class for: LogBean
 *
 */
@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
        @ActivationConfigProperty(propertyName="destination", propertyValue="queue/JBQueue")        
    }, 
	mappedName = "LogBean",
	name="LogBean",
	description="LogBean Test")     

public class LogBean implements MessageListener {

    /**
     * Default constructor. 
     */
    public LogBean() {
        System.out.println("LogBean created");
    }
	
	/**
     * @see MessageListener#onMessage(Message)
     */
    public void onMessage(Message message) {
        System.out.println("onMessage called");
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            try {
                String text = tm.getText();
                System.out.println("Received new message : " + text);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
        
    }

    @PreDestroy
    public void remove() {
        System.out.println("LogBean destroyed.");
    }

}
